package Logic.EbSample;

import FrameWork.EventBus.Anno.Receiver;
import FrameWork.EventBus.Anno.Schedule;
import FrameWork.EventBus.ScheduleType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class SomeService {

    private int amount;

    @Receiver
    @Schedule(ScheduleType.ACTOR)
    public void handlerE(AfterLoginEvent event){
        amount += 1;
    }

    @Receiver
    @Schedule(ScheduleType.SYNC)
    public void handleA(AfterLoginEvent event){
        System.out.println("very important!立刻执行");
    }

    @Receiver
    public void normalHandlerB(AfterLoginEvent event){
        System.out.println(event.getPlayer().getDispatcherCode());
    }

    @Receiver
    @Schedule(ScheduleType.ASYNC)
    public void handlerC(AfterLoginEvent event){
        System.out.println(Thread.currentThread().getName());
    }



    @Receiver
    @Schedule(ScheduleType.WORKER)
    public void blockHandlerD(AfterLoginEvent event){
        //做耗时操作
        try {
            System.out.println("doBlocking:"+Thread.currentThread().getName());
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
